<!-- templates/upload.html -->
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>上传知识 - 花艺AI测试应用</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body { padding-top: 2rem; }
        .header { margin-bottom: 2rem; }
        .form-container { max-width: 800px; margin: 0 auto; }
    </style>
</head>
<body>
    <div class="container">
        <div class="header text-center">
            <h1>花艺AI测试应用</h1>
            <p class="lead">上传知识文档到系统</p>
            <nav class="nav justify-content-center">
                <a class="nav-link" href="/">首页</a>
                <a class="nav-link" href="/upload">上传知识</a>
                <a class="nav-link" href="/image">生成图像</a>
                <a class="nav-link" href="/status">系统状态</a>
            </nav>
        </div>
        
        <div class="form-container">
            <div class="card">
                <div class="card-header bg-warning">
                    <h5 class="mb-0">上传知识文档</h5>
                </div>
                <div class="card-body">
                    <form id="uploadForm" enctype="multipart/form-data">
                        <div class="mb-3">
                            <label for="file" class="form-label">选择PDF或TXT文件:</label>
                            <input class="form-control" type="file" id="file" name="file" accept=".pdf,.txt" required>
                        </div>
                        <button type="submit" class="btn btn-warning">上传文档</button>
                    </form>
                    
                    <div id="uploadResult" class="mt-3 d-none">
                        <div class="alert alert-info">
                            <span id="resultMessage"></span>
                        </div>
                    </div>
                </div>
                <div class="card-footer text-muted">
                    支持的文件格式: PDF, TXT
                </div>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.getElementById('uploadForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const formData = new FormData(this);
            const resultDiv = document.getElementById('uploadResult');
            const resultMessage = document.getElementById('resultMessage');
            
            fetch('/upload', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                resultDiv.classList.remove('d-none');
                resultMessage.textContent = data.message || JSON.stringify(data);
            })
            .catch(error => {
                resultDiv.classList.remove('d-none');
                resultMessage.textContent = '上传失败: ' + error;
            });
        });
    </script>
</body>
</html>
